Repository navigation
Conversation
When the installed graphql doesn't provide @defer/@stream, Grafast already polyfills the directives themselves, but their usage wasn't validated. Add polyfills of the GraphQL.js v17 incremental delivery validation rules (label uniqueness/staticness, no defer/stream on root mutation/subscription fields, disabled-only in subscriptions, @stream on list fields only, and no overlapping fields with @stream), exported as `incrementalValidationRules`. These are applied by `grafast()` and by Grafserv's default validation rules; the list is empty when graphql already ships these rules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 4036870 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Author
|
@codex review |
The individual polyfill rules are an implementation detail; nothing needs them and they'd become obsolete public API once graphql@17 is required. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StreamDirectiveOverlappingFieldsRule could recurse forever on fragment cycles (throwing RangeError from validate()) and took exponential time on fragment fan-out, both triggerable by any document containing @stream. - Memoise check() on the group of selection sets being merged - Only compare pairs involving a @stream field; dedupe fields with a Set - Report each conflicting pair once regardless of order - Skip the rule entirely when the schema has no @stream directive Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
We're hoping to punt this to just use the GraphQL v17 rules rather than copying them into Grafast |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to the discussion about supporting
@defer/@streamwithout a specificgraphqlversion.When the installed
graphqldoesn't provide@defer/@stream(e.g.graphql@^16), Grafast already polyfills the directives themselves (incremental.ts, added to the schema byStreamDeferPlugin/makeGrafastSchema({ enableDeferStream: true })). What was missing is validation of how those directives are used, since GraphQL.js 16'sspecifiedRulesknow nothing about them.This PR adds polyfills of the GraphQL.js v17 incremental delivery validation rules (written from the 17.x.x behaviour, not copied), in
grafast/src/incrementalValidation.ts:DeferStreamDirectiveLabelRule– labels must be static strings, unique across the documentDeferStreamDirectiveOnRootFieldRule– no@defer/@streamon root mutation/subscription selectionsDeferStreamDirectiveOnValidOperationsRule– in subscriptions, only allowed when disabled (if: falseor a variable)StreamDirectiveOnListFieldRule–@streamonly on list fieldsStreamDirectiveOverlappingFieldsRule– the@streampart of v17'sOverlappingFieldsCanBeMergedRule; Grafast's planner relies on thisOnly the aggregate is exported, as
incrementalValidationRules; it's applied bygrafast()and Grafserv's defaultvalidationRules. The list is empty whengraphqlalready provides@defer/@stream, so rules never run twice.Notes for review
@streamis a conflict, even with identical arguments — see Same stream across fragments graphql/defer-stream-wg#100) rather than the pre-2023SameStreamDirective. It rejects a superset of what the old rule did, so it's safe for the current implementation, and documents accepted today stay valid once Grafast moves to the modern incremental delivery format. Happy to switch to the looser rule if you'd prefer.if/initialCountargs are still nullable (v17 usesBoolean! = true/Int! = 0); changing them would alter printed schemas, so I left that alone.graphqlHasStreamDeferis true,StreamDeferPlugin/makeGrafastSchemaassume the old experimentalgraphql@16API (enableDeferStream, no directives added). On v17 I believe the directives won't reach the schema. Not tested on v17; likely part of the move to the modern format.grafast/envelop'suseGrafast()only replaces execute/subscribe, so Envelop/Yoga users ongraphql@16still won't get these rules unless they addincrementalValidationRulesthemselves. This gap predates the PR; I left it out to keep scope tight, but it's a ~5 lineonValidatehook if you'd like it here.incrementalValidationRulesfromgrafast, but its peer range is still^1.0.0-rc.8. A new Grafserv with an older Grafast would fail at startup. I didn't bump the range (AGENTS.md: avoid version changes unless essential) — let me know if you'd like it bumped.StreamDeferPluginis still not in graphile-build's default preset, so this PR doesn't change that it's opt-in.Performance impact
Negligible: the overlap rule is skipped entirely if the schema has no
@stream, memoises each merged group of selection sets (so fragment cycles and fan-out can't blow up), and only compares pairs involving a@streamfield. The other four simple rules do cheap per-directive/per-operation checks; the overlap rule only does its work if the document contains a@streamdirective.Testing
grafast/__tests__/incrementalValidation-test.ts(10 tests, including viagrafast(), plus regression tests for fragment cycles, fragment fan-out and duplicate reports).specifiedRulesalone.test-bundlepasses.*.test.graphqldocuments using@stream/@deferagainst the example schema with the new rules — no new errors. (Note those test helpers call plainvalidate(), so they don't exercise these rules.)Security impact
Improves robustness: previously invalid
@defer/@streamusage could reach the planner unvalidated ongraphql@16.Checklist
yarn lint:fixpasses.🤖 Generated with Claude Code